
// 1.确认修改
$('.layui-form').on('submit', function (e) {
    e.preventDefault()
    let data = $(this).serialize()
    $.ajax({
        type: 'POST',
        url: '/my/user/updatepwd',
        data: data,
        success: function (res) {
            if (res.status === 0) {
                layer.msg(res.message, {
                    icon: 1,
                    time: 1500
                }, function () {
                        localStorage.removeItem('token')
                        window.parent.location.href = '../login.html'
                    }
                )
               
            } else {
                layer.msg(res.message,{icon: 2})
            }
        }
    })
})

// 2.表单验证
let form = layui.form
form.verify({
    // 1.密码长度设置
    pass: [/^\S{6,12}$/, '密码必须为6-12位'],
    // 2.新密码不能和旧密码一样
    newPass: function (abc) {
        if ($('input[name = oldPwd]').val() === abc) {
            return '新密码不能和原密码一致'
        }
    },
    // 3.确认密码要和新密码一致
    same: function (abc) {
        if ($('input[name = newPwd]').val() !== abc) {
            return '两次密码输入不一致'
       }
    }

})
